package com.app.controller.supermarket;

import com.app.mapper.ConfigMapper;
import com.app.mapper.supermarket.FeedbackMapper;
import com.app.model.ConfigModel;
import com.app.model.supermarket.FeedbackModel;
import com.app.model.supermarket.MktPersonModel;
import com.app.service.supermarket.MktPersonService;
import com.app.util.BizException;
import com.app.util.Result;
import com.app.util.TokenUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiOperation;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description: 意见反馈控制层
 * @Date: 2022/11/14 10:14
 */
@RestController
@RequestMapping("api/feedback")
public class FeedbackController {
    @Autowired
    private FeedbackMapper feedbackMapper;

    @Autowired
    private MktPersonService mktPersonService;



    @ApiOperation("反馈意见")
    @RequestMapping(value = "/addFeedback", method = RequestMethod.POST)
    public Result<Object> addFeedback(Integer type, String content, HttpServletRequest request) {
        String token = request.getHeader("token");
        if(token==null)
        {
            return Result.error(405,"token不存在");
        }
        String mobile = TokenUtils.verify(token);
        MktPersonModel customer = mktPersonService.getModelByMobile(mobile);
        if(customer==null)
        {
            return Result.error(405,"用户不存在");
        }
        FeedbackModel feedback = new FeedbackModel();
        feedback.setType(type);
        feedback.setContent(content);
        feedbackMapper.insert(feedback);

        return Result.success("操作成功");
    }


}
